import { Inject, Controller, Post, File } from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { ApiTags } from "@midwayjs/swagger";
import { Utils } from "../utils/index";
import { CosService } from "../service/cos.service";
import { UploadFileInfo } from "@midwayjs/upload";

@ApiTags("cosv5文件处理")
@Controller()
export class CosFileController {
  @Inject()
  ctx: Context;

  @Inject()
  cosService: CosService;

  @Inject()
  utils: Utils;

  @Post("/auth-api/cosv5/upload")
  async upload(@File() file: UploadFileInfo<any>) {
    if (!file) {
      return this.utils.response.fail({
        message: "上传文件不能为空"
      });
    }
    const result = await this.cosService.putFileObject(file);
    return {
      ...this.utils.response.success({ ...result })
    };
  }
}
